var t = require("../../@babel/runtime/helpers/toConsumableArray"),
  a = require("../../utils/http.js"),
  e = require("../../utils/api.js"),
  i = require("../../utils/language/switchLanguage.js");
Page({
  data: {
    languageType: "",
    tablist: ["全部订单", "待支付", "待使用", "已退款"],
    tab: 0,
    lists: { list: [], page: 1, limit: 15 },
    refresh: !1,
    orderStatus: {},
    winHeight: 0,
    sourceType: 1,
    show: !0,
  },
  onLoad: function (t) {
    e.isExitOpenId("plugin://order/order-page"),
      this.initLanguage(),
      this.setData({
        params: {
          sourceType: this.data.sourceType,
          orderStatusArray: "",
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        },
        skey: t.skey,
        openId: requireMiniProgram().getOpenId(),
      }),
      wx.setStorageSync("skey", t.skey);
    var a = {};
    switch (this.data.tab) {
      case 0:
        (a = {
          sourceType: this.data.sourceType,
          orderStatusArray: "",
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        }),
          "" != wx.getStorageSync("token")
            ? this.getOrderList(a)
            : this.getOpenId();
        break;
      case "1":
        a = {
          sourceType: this.data.sourceType,
          orderStatusArray: 0,
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        };
        break;
      case "2":
        a = {
          sourceType: this.data.sourceType,
          orderStatusArray: "1,12",
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        };
        break;
      case "3":
        a = {
          sourceType: this.data.sourceType,
          orderStatusArray: 4,
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        };
    }
    this.setData({ params: a });
  },
  onShow: function () {
    if (wx.getStorageSync("isRefresh") && 0 != this.data.tab) {
      var t = this.data.lists;
      (t.list = []),
        (t.page = 1),
        this.setData({ lists: t }),
        wx.removeStorageSync("isRefresh"),
        this.getOrderList(this.data.params);
    }
  },
  switchLanguage: function (t) {
    "english" == t.target.dataset.language
      ? i.changLanguage(0)
      : i.changLanguage(1),
      this.initLanguage();
  },
  initLanguage: function () {
    var t = i.languageVersion(wx.getStorageSync("language"));
    this.setData({ _t: t, languageType: wx.getStorageSync("language") }),
      wx.setNavigationBarTitle({ title: t["订单列表"] });
  },
  getOpenId: function () {
    var t = this,
      i = {
        appNo: "wx393d60d93f70599c",
        openId: this.data.openId,
        configType: 1,
        loginType: 2,
        accessToken: this.data.skey,
      };
    a.threeWayLogin(i).then(function (a) {
      if (null == a.uid)
        return (
          e.showMsg(t.data._t["登录过期，请重新登录"]),
          void wx.navigateTo({
            url: "/pages/mine-index/login/index?redirectUrl=".concat(
              encodeURIComponent("plugin://order/order-page"),
              "&type=4",
            ),
          })
        );
      t.setData({
        museumMerchant: a.museumMerchant,
        isTeam: a.isTeam,
        teamType: a.teamType,
      }),
        wx.setStorageSync("token", a.token),
        wx.setStorageSync("openId", a.openId),
        wx.setStorageSync("telphoneNumber", a.contactsPhone),
        wx.setStorageSync("museumMerchant", a.museumMerchant),
        wx.setStorageSync("merchantNo", a.museumMerchant.merchantNo),
        t.getOrderList(t.data.params);
    });
  },
  getOrderList: function (e, i) {
    var r = this;
    a.getOrderList(e).then(function (a) {
      if (
        (void 0 !== i && i(a.data.rows),
        a.data.rows.length > 0 && !r.data.refresh)
      ) {
        var s = r.data.lists;
        (s.list = [].concat(t(s.list), t(a.data.rows))),
          (s.page = e.page),
          r.setData({ lists: s, lock: !1, total: a.data.total }),
          r.get_height(".all");
      } else if (a.data.rows && r.data.refresh) {
        var n = r.data.lists;
        (n.list = a.data.rows),
          (n.page = e.page),
          r.setData({ lists: n, refresh: !1, lock: !1, total: a.data.total }),
          r.get_height(".all");
      }
      r.setData({ show: !0 });
    });
  },
  CancelOrder: function (t) {
    var i = t.currentTarget.dataset.orderno,
      r = this;
    wx.showModal({
      title: r.data._t["提示"],
      content: r.data._t["是否确认取消？"],
      confirmText: r.data._t["确定"],
      cancelText: r.data._t["取消"],
      success: function (t) {
        if (t.confirm) {
          var s = { merchantNo: wx.getStorageSync("merchantNo"), orderSn: i };
          wx.showLoading({ title: r.data._t["退订中"] }),
            a.CancelOrder(s).then(function (t) {
              e.showMsg(r.data._t["取消成功"]), wx.hideLoading();
              var a = r.data.lists;
              (a.list = []),
                (a.page = 1),
                r.setData({ lists: a }),
                r.getOrderList(r.data.params);
            });
        }
      },
    });
  },
  subForm: e.throttle(function (t) {
    var a = t[0].currentTarget.dataset.orderno;
    this.wechatPay(a);
  }),
  wechatPay: function (t) {
    var i = this,
      r = {
        merchantNo: wx.getStorageSync("merchantNo"),
        tradeType: "wxSmallPay",
        payType: 4,
        payConfigType: 4,
        orderNo: t,
      },
      s = e.encryptBASE64(JSON.stringify(r)),
      n = { sign: e.autograph(s), signData: s },
      o = this;
    a.wechatPay(n).then(function (t) {
      requireMiniProgram()
        .requestPayment(t.data)
        .then(function (t) {
          "requestPayment:ok" == t.errMsg &&
            (wx.showLoading({ title: i.data._t["支付处理中"] + "..." }),
            setTimeout(function () {
              wx.hideLoading();
              var t = o.data.lists;
              (t.list = []),
                (t.page = 1),
                o.setData({ lists: t }),
                o.getOrderList(o.data.params);
            }, 1e3));
        })
        .catch(function (t) {
          "requestPayment:fail cancel" != t.errMsg &&
            "requestPayment:fail" != t.errMsg &&
            wx.showModal({
              title: i.data._t["通知"],
              showCancel: !1,
              content: i.data._t["调起支付失败，请稍后重试"] + "...",
              confirmText: i.data._t["确认"],
            });
        });
    });
  },
  get_height: function (t) {
    var a = this;
    setTimeout(function () {
      wx.createSelectorQuery()
        .in(a)
        .select(t)
        .boundingClientRect(function (t) {
          var e = t.height;
          t.width;
          a.setData({ winHeight: e });
        })
        .exec();
    }, 200);
  },
  changNav: function (t) {
    this.setData({ tab: t.target.dataset.id });
  },
  switchTab: function (t) {
    var a = this.data.lists;
    (a.list = []),
      (a.page = 1),
      this.setData({ tab: t.detail.current, lists: a, show: !1, winHeight: 0 });
    var e = {};
    switch (this.data.tab) {
      case 0:
        e = {
          sourceType: this.data.sourceType,
          orderStatusArray: "",
          page: this.data.lists.page,
          limit: this.data.lists.limit,
        };
        break;
      case 1:
        e = {
          sourceType: this.data.sourceType,
          page: this.data.lists.page,
          limit: this.data.lists.limit,
          orderStatusArray: 0,
        };
        break;
      case 2:
        e = {
          sourceType: this.data.sourceType,
          page: this.data.lists.page,
          limit: this.data.lists.limit,
          orderStatusArray: "1,12",
        };
        break;
      case 3:
        e = {
          sourceType: this.data.sourceType,
          page: this.data.lists.page,
          limit: this.data.lists.limit,
          orderStatusArray: 4,
        };
    }
    this.getOrderList(e), this.setData({ params: e });
  },
  toInvoice: function () {
    wx.navigateTo({
      url: "plugin-private://wx393d60d93f70599c/pages/invoice/index",
    });
  },
  toPage: function (t) {
    var a = t.currentTarget.dataset.idx,
      e = this.data.lists.list,
      i = e[a].orderStatus;
    0 != i || 0 != e[a].orderType
      ? 0 != i || 1 != e[a].orderType
        ? 1 != i || 0 != e[a].orderType
          ? 12 != i || 0 != e[a].orderType
            ? 5 != i || 0 != e[a].orderType
              ? (1 != i && 12 != i) || 1 != e[a].orderType
                ? 2 != i || 1 != e[a].orderType
                  ? (6 != i && 3 != i && 4 != i) || "1" != e[a].orderType
                    ? (2 != i && 3 != i && 4 != i && 11 != i) ||
                      0 != e[a].orderType
                      ? 7 != i
                        ? 13 != i
                          ? 14 != i ||
                            wx.navigateTo({
                              url: "plugin-private://wx393d60d93f70599c/pages/TicketFail/index?orderNo=".concat(
                                e[a].orderSn,
                              ),
                            })
                          : wx.navigateTo({
                              url: "plugin-private://wx393d60d93f70599c/pages/Ticketsing/index?orderNo=".concat(
                                e[a].orderSn,
                              ),
                            })
                        : wx.navigateTo({
                            url: "plugin-private://wx393d60d93f70599c/pages/teamFail/index?orderNo=".concat(
                              e[a].orderSn,
                            ),
                          })
                      : wx.navigateTo({
                          url: "plugin-private://wx393d60d93f70599c/pages/Used/index?orderNo=".concat(
                            e[a].orderSn,
                          ),
                        })
                    : wx.navigateTo({
                        url: "plugin-private://wx393d60d93f70599c/pages/Review/index?orderNo=".concat(
                          e[a].orderSn,
                        ),
                      })
                  : wx.navigateTo({
                      url: "plugin-private://wx393d60d93f70599c/pages/teamUsed/index?orderNo=".concat(
                        e[a].orderSn,
                      ),
                    })
                : wx.navigateTo({
                    url: "plugin-private://wx393d60d93f70599c/pages/teamUnused/index?orderNo=".concat(
                      e[a].orderSn,
                    ),
                  })
              : wx.navigateTo({
                  url: "plugin-private://wx393d60d93f70599c/pages/outTime/index?orderNo=".concat(
                    e[a].orderSn,
                  ),
                })
            : wx.navigateTo({
                url: "plugin-private://wx393d60d93f70599c/pages/activateOrder/index?orderNo=".concat(
                  e[a].orderSn,
                ),
              })
          : wx.navigateTo({
              url: "plugin-private://wx393d60d93f70599c/pages/Unused/index?orderNo=".concat(
                e[a].orderSn,
              ),
            })
        : wx.navigateTo({
            url: "plugin-private://wx393d60d93f70599c/pages/Approved/index?orderNo=".concat(
              e[a].orderSn,
            ),
          })
      : wx.navigateTo({
          url: "plugin-private://wx393d60d93f70599c/pages/Unpay/index?orderNo=".concat(
            e[a].orderSn,
          ),
        });
  },
  onPullDownRefresh: function () {
    this.setData({ refresh: !0 }, function () {
      var t = this.data.params;
      (t.page = 1),
        this.getOrderList(t, function (t) {
          wx.stopPullDownRefresh();
        });
    });
  },
  onReachBottom: function () {
    if (this.data.total != this.data.lists.list.length && !this.data.lock) {
      this.setData({ lock: !0 });
      var t = this.data.params;
      (t.page = this.data.lists.page + 1), this.getOrderList(t);
    }
  },
  onReady: function () {},
  onHide: function () {},
  onUnload: function () {},
});
